Re: [INTERFACES] Questions about INSERT INTO! - Mailing list pgsql-interfaces

From Herouth Maoz
Subject Re: [INTERFACES] Questions about INSERT INTO!
Date
Msg-id l03130300b3701f13c24c@[147.233.159.109]
Whole thread Raw
In response to Questions about INSERT INTO!  ("Anna Langer" <anna_langer@hotmail.com>)
List pgsql-interfaces
At 10:54 +0300 on 25/05/1999, Anna Langer wrote:


> Now we wonder if we can put the date in to the database in the same way that
> we did with the integers? We have tried to make the date to a string, but it
> doesn't take it. The errormessage say that the database is of type datetime
> and the string is of type int4.
>
> Is there anyone who can help us with this?
>
> Thanks!

You really must learn C. The trick with the %d is the standard way in C of
converting integers into strings. Dates are a bit more complicated. What is
the type you use for dates? time_t? If so, you convert it to string using
ctime(), a function in the standard C library. And then you use sprintf and
place it within single quotes.

It's true for every data type. You have to convert it to string, and then
have that string inserted into the command string using sprintf, with %s
within quotes. In the case of integer, the two steps can be shortened into
one, and you don't need quotes around the value. Same goes for float. Any
other data type needs the two steps and quotes.

Once you master this, remember that if your datatype is string, you have to
make sure every quote within the string is doubled (or preceded with a
backslash, but that's non-standard) before you pass it.

Herouth

--
Herouth Maoz, Internet developer.
Open University of Israel - Telem project
http://telem.openu.ac.il/~herutma




pgsql-interfaces by date:

Previous
From: "Anna Langer"
Date:
Subject: Questions about INSERT INTO!
Next
From: Herouth Maoz
Date:
Subject: Re: [GENERAL] JDBC and insert - stack overflow